﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TXK
{
    class Helper
    {
        /// <summary>
        /// 判断是否产生报警
        /// </summary>
        /// <param name="current">当前值</param>
        /// <param name="set">设定值</param>
        /// <param name="last">缓冲值</param>
        /// <param name="isPositive">正向或反向检测</param>
        /// <returns>返回结果，1表示触发，-1表示消除，0表示无变化</returns>
        public static int IsAlarm(float current, float set, float last, bool isPositive)
        {
            if (isPositive)
            {
                if (current >= set && last < set)
                {
                    return 1;
                }
                if (current < set && last >= set)
                {
                    return -1;
                }
            }
            else
            {
                if (current <= set && last > set)
                {
                    return 1;
                }
                if (current > set && last <= set)
                {
                    return -1;
                }
            }
            return 0;
        }
    }
}
